//
//  PopoverPresentationController.swift
//  WeiBo(Swift)
//
//  Created by 周成龙 on 16/9/25.
//  Copyright © 2016年 ZCL. All rights reserved.
//

import UIKit

class PopoverPresentationController: UIPresentationController {
    
    
    var presentFrame = CGRect.zero
    
    
    override func containerViewWillLayoutSubviews() {
        
        // containerView: 容器
        // presentedView: 拿到弹出视图
        
        guard let view = presentedView else {
            return
        }
        view.backgroundColor = UIColor.clear
        view.frame = presentFrame // CGRect(x: UIScreen.main.bounds.width*0.5 - 100, y: 45, width: 200, height: 200)
        
        containerView?.insertSubview(dismissButton, at: 0)
        dismissButton.addTarget(self, action: #selector(PopoverPresentationController.dismissButtonClick), for: UIControlEvents.touchUpInside)
    }
    
    @objc private func dismissButtonClick() {
        // 消失 vc
        presentedViewController.dismiss(animated: true, completion: nil)
    }
    
    private lazy var dismissButton: UIButton = {
        let btn = UIButton()
        btn.frame = UIScreen.main.bounds
        return btn
    }()
    
}
